<?php 
include_once("inc/connection.php");
include_once("inc/constants.inc.php");
session_start();

if(!isset($_SESSION['login']) || empty($_SESSION['login']) || !isset($_SESSION['email']) || empty($_SESSION['email']) || !isset($_SESSION['user_role']))
	{
		header("Location: login.php?error=invalid-access");
		exit(0);
	}
elseif($_SESSION['user_role']==2)
	{
		header("Location: test.php?error=invalid-access");
		exit(0);
	}
if(isset($_GET['isUpdated']) && $_GET['isUpdated']=="yes" && isset($_GET['isReset']) && $_GET['isReset']=="yes")
	{
		$updated = true;
	}
function domainMapper($number){
	switch ($number) {
		case "1":
			return "Java";
			break;
		case "2":
			return "PHP";
			break;
		case "3":
			return ".NET";
			break;
		case "4":
			return "SharePoint";
			break;
		case "5":
			return "iOS";
			break;
		case "6":
			return "ROR";
			break;
		case "7":
			return "Big data";
			break;
		case "8":
			return "Testing";
			break;
	}
}
	
?>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>Smartek online test | Dashboard</title>
		<link rel="SHORTCUT ICON" href="img/disp/favicon.png" />	
		<link rel="stylesheet" href="css/bootstrap.css"  type="text/css"/>
		<script src="js/jquery-ui.js" type="text/javascript"></script> 
		<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
		
		<script type="text/javascript">
			function resetMarks(studentId){
				$('#confirm_popup').removeClass("hide"); 
				$("#confirm_popup").show();
				$("#confirm_popup").css('top',$(window).scrollTop()+200);
				$('#confirm_content').html('Do you really want to reset?');
				$('#confirm_no').click(function(){
						 $("#confirm_popup").hide();
						return false;
				});
				$('#confirm_yes').click(function(){
					$.get( "ajax/reset-marks.php?studentId="+studentId, function( data ) {
						location.reload();
					});				
				});				
			}
		</script>
		<script language="javascript" type="text/javascript">
        $(document).ready(function() {
                $('#search').keyup(function() {
                        searchTable($(this).val());
                });
        });
        function searchTable(inputVal) {
                var table = $('#searchTable');
                table.find('tr').each(function(index, row) {
                        var allCells = $(row).find('td');
                        if (allCells.length > 0) {
                                var found = false;
                                allCells.each(function(index, td) {
                                        var regExp = new RegExp(inputVal, 'i');
                                        if (regExp.test($(td).text())) {
                                                found = true;
                                                return false;
                                        }
                                });
                                if (found == true)
                                        $(row).show();
                                else
                                        $(row).hide();
                        }
                });
        }
		</script>	
	</head>
	<body>
		<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
		<script src="js/bootstrap.js"></script>
		
		<div class="container">
			<a href="index.php"><img src="img/disp/logo.png" alt=""></a>
		</div>
		
		<div class="container">
			<a href="logout.php" class="pull-right">Logout</a>
		</div>
		
		<div class="container">
			<hr class="featurette-divider">
		</div>
		
		<div id="confirm_popup" class="hide">
			<div id="confirm_content"></div>
			<br/><br/>
			<input id='confirm_yes' type='button' class="btn btn-default" value='Yes' />
			<input id='confirm_no' type='button' class="btn btn-primary" value='No' />
		</div>	

		<div class="container">
			<div class="row">
				<div class="span12" > <!--pagination-centered-->

						<a href="select-type-admin.php">Add Question</a> 
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;						
						<a href="show-question-list.php">View Question List</a>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<a href="manage-time.php">Manage Exam Time</a>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<a href="reset-user-password.php">Reset User Password</a><br/><br/>					
					<?php if(isset($updated) && $updated) { echo "<font color='blue'> Password updated successfully !</font>" ;} ?>			
					<div id="dashboard">					
						<div class="container">
							<div class="row pull-right">
								<div class="span4 pull-right" >
									<div class="pull-right">
										<input style="" type="text" placeholder="search here . . ." id="search">
									</div>
								</div>
							</div>
						</div>
						<table class='table table-bordered table-striped' id='searchTable'>
							<tr>
								<th>Name</th>
								<th>Company</th>
								<th>Domain</th>
								<th>Experience</th>
								<th>Gender</th>
								<th>Email</th>
								<th>Mobile Number</th>
								<th>Marks</th>							
							</tr>						
							<?php								
								$result = mysql_query("SELECT * FROM login_details WHERE UserRole='2'");				
								while($row = mysql_fetch_array($result))
									{
										$countMarks = 0;
										echo "<tr>";
											echo "<td><a href='show-answer-sheet.php?studentID=$row[userID]'>" . $row['UserName'] . "</td>";
											echo "<td>" . $row['company'] . "</td>";						
											echo "<td>" . domainMapper($row['domain']) . "</td>";	
											echo "<td>" . $row['experience'] . "</td>";	
											echo "<td>" . $row['UserGender'] . "</td>";
											echo "<td>" . $row['UserEmail'] . "</td>";
											echo "<td>" . $row['mobileNo'] . "</td>";											
											$userId = $row['userID'];
											$req = mysql_query("SELECT * FROM answer_sheet WHERE StudentID='$userId' && isReset='no' && Result='correct'");				
											while($res = mysql_fetch_array($req))
											{	
												$countMarks++;
											}
											echo "<td>" . $countMarks ."  ". "<a href='#' id='reset' onClick='resetMarks($userId)'>  Reset Marks</td>";
										echo "</tr>";
									}
								/*
								$countApti = 0;
								$countCS = 0;
								$result = mysql_query("SELECT * FROM login_details WHERE UserRole='2'");				
								while($row = mysql_fetch_array($result))
									{	
										echo "<tr>";
											echo "<td><a href='show-answer-sheet.php?studentID=$row[userID]'>" . $row['UserName'] . "</td>";
											echo "<td>" . $row['UserCollege'] . "</td>";						
											echo "<td>" . $row['UserRollNo'] . "</td>";	
											echo "<td>" . $row['UserGender'] . "</td>";	
											echo "<td>" . $row['UserEmail'] . "</td>";
											
											$userId = $row['userID'];						
											$result1 = mysql_query("SELECT * FROM answer_sheet WHERE StudentID='$userId' && isReset='no'");				
											while($row1 = mysql_fetch_array($result1))
												{	
													if($row1['Result'] == "correct" && $row1['typeId'] == 1){$countApti++;}
													elseif($row1['Result'] == "correct" && $row1['typeId'] == 2){$countCS++;}
												}
											echo "<td>" . $countApti . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' id='reset' onClick='resetMarks($userId, 1)'>Reset Marks</td>";
											echo "<td>" . $countCS . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' id='reset' onClick='resetMarks($userId, 2)'>Reset Marks</td>";
											$total = $countApti + $countCS ; 
											echo "<td>" . $total . "</td>";
											$countApti = 0;
											$countCS = 0;
										echo "</tr>";						
									}					
								*/
							?>
								
						</table>	
					</div>
				</div>
			</div>
		</div>

		
		<div class="container marketing">
      <!-- FOOTER -->
		<div class="container">
			<hr class="featurette-divider">
		</div>
      <footer>
        <p>&copy; 2014 SCS &middot; </p>
      </footer>

    </div><!-- /.container -->
	</body>
</html>